package com.sugar.web.action.oa.hr;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.sugar.common.base.persistence.query.PageView;
import com.sugar.common.tools.ParseArrayUtil;
import com.sugar.domain.oa.hr.Department;
import com.sugar.service.oa.hr.IDepartmentService;
import com.sugar.web.action.base.BaseActionSupport;

@Controller
@Scope("prototype")
public class DepartmentAction extends BaseActionSupport {

	private static final long serialVersionUID = 1L;

	private Department dept;

	private String delIds;
	
	private String type ;

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getDelIds() {
		return delIds;
	}

	public void setDelIds(String delIds) {
		this.delIds = delIds;
	}

	@Resource
	private PageView<Department> pageView;

	public PageView<Department> getPageView() {
		return pageView;
	}

	public void setPageView(PageView<Department> pageView) {
		this.pageView = pageView;
	}

	public Department getDept() {
		return dept;
	}

	public void setDept(Department dept) {
		this.dept = dept;
	}

	@Resource
	private IDepartmentService depts;

	public String findDeptAction() {

		getRequest().setAttribute("dept", this.depts.findDeptService(null));

		return SUCCESS;
	}

	public String getDeptAction() {

		getRequest().setAttribute("dept",
				this.depts.loadDeptByIdService(dept.getDeptNo()));

		if("update".equals(type)) {
			return "update" ;
		} else {
			return "get" ;
		}
	}

	public String updateDeptAction() {

		this.depts.updateDeptService(dept);

		return "updateSuccess";
	}

	public String getScrollDeptAction() {

		this.pageView.setPageModel(this.depts.getScorllDeptService(null,
				this.pageView.getFirstResult(), this.pageView.getMaxResult()));

		getRequest().setAttribute("pageView", pageView);

		return "getScrollSuccess";
	}

	public String deleteSelectOrgAction() {

		this.depts.deleteSelectDeptService(ParseArrayUtil.parseArray(delIds));

		return "deleteSelectSuccess";
	}

	public String addDeptAction() {

		this.depts.saveDeptService(dept);

		return "addDeptSuccess";
	}

}
